import string


words = []
with open("word.txt", "r") as f:
    for i in f:
        str1 = i
        str2 = str1.lower()
        if str2.split() != "":
            words.extend(str2.split())
b = []
for i in words:
    if i[-1] in string.printable[62:]:
        i = i[0:-1]
        b.append(i)
    else:
        b.append(i)
d = {}
for i in b:
    if i.isalpha():
        if i not in d:
            d[i] = 0
        d[i] = d.get(i) + 1

t = []
for i, j in d.items():
    t.append(j)

t.sort(reverse=1)
t2 = t[0:10]

print("瓦尔登湖频率前十单词统计如下：")
for i, m in enumerate(t2):
    for k, j in d.items():
        if j == m:
            print(f"第{i + 1}名是:{k}出现次数为{j}")
